/*
package com.zmn.oms.task.job.third.pinduoduo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.spring.tasktracker.JobRunnerItem;
import com.github.ltsopensource.spring.tasktracker.LTS;
import com.github.ltsopensource.tasktracker.Result;
import com.zmn.common.dto.ResultDTO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.manager.lts.interfaces.task.TaskManager;
import com.zmn.oms.business.interfaces.third.PinDuoDuoSignShopService;
import com.zmn.oms.manager.utils.TaskConsts;
import com.zmn.oms.model.entity.third.PinDuoDuoSignShop;
import com.zmn.oms.third.pinduoduo.PinDuoDuoConsts;
import com.zmn.oms.third.pinduoduo.dto.api.PinDuoDuoResponse;
import com.zmn.oms.third.pinduoduo.dto.api.PinDuoDuoSendSign;
import com.zmn.oms.third.pinduoduo.service.PinDuoDuoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

*/
/**
 * 类描述：拼多多签约结果回传
 *
 * @author wangxiaokun
 * @since 2020/5/3121:43
 *//*

@LTS
@Slf4j
public class PinDuoDuoSignNotifyJob {

    @Autowired
    private PinDuoDuoService pinDuoDuoService;

    @Autowired
    private PinDuoDuoSignShopService pinDuoDuoSignShopService;

    @Resource
    TaskManager taskManager;

    */
/**
     * 每隔1分钟，查询拼多多已签约或已拒绝没有发送签约结果的店铺信息
     *//*

    @PostConstruct
    void init() {
        Job job = new Job();
        job.setTaskId(TaskConsts.TASK_PDD_CHECK_SYNC_STATUS_JOB);
        job.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_PDD_CHECK_SYNC_STATUS_JOB);
        job.setCronExpression("0 /10 * * * ?");
        job.setReplaceOnExist(true);
        ResultDTO result = taskManager.submitTask(job);
        if (!result.getStatusBool()) {
            log.error("#oms#pinduoduo_sign_notify# job submit fail...");
        }
    }

    @JobRunnerItem(shardValue = TaskConsts.TASK_PDD_CHECK_SYNC_STATUS_JOB)
    public Result checkSyncStatus(){
        // 判断拼多多渠道开关
        if (!PinDuoDuoConsts.POWER_ON){
            log.info("【{}】<检查是否同步签约结果> 该功能没有开启。", PinDuoDuoConsts.CHANNEL_NAME);
            return null;
        }

        log.info("【{}】开始检查已签约或已拒绝，没有同步签约结果店铺", PinDuoDuoConsts.CHANNEL_NAME);
        List<PinDuoDuoSignShop> list = pinDuoDuoSignShopService.listPinDuoDuoSignShopBySyncStatus();
        if (CollectionUtil.isNotNullOrEmpty(list)){
            for (PinDuoDuoSignShop pinDuoDuoSignShop : list){
                PinDuoDuoSendSign pinDuoDuoSendSign = new PinDuoDuoSendSign();
                // 如果已签约没有同步
                if (pinDuoDuoSignShop.getSignStatus() == 1){
                    pinDuoDuoSendSign.setSignOrderSn(pinDuoDuoSignShop.getSignOrderSn());
                    pinDuoDuoSendSign.setMallId(pinDuoDuoSignShop.getMallId());
                    pinDuoDuoSendSign.setServType(pinDuoDuoSignShop.getServType());
                    pinDuoDuoSendSign.setVerifyStatus(PinDuoDuoConsts.PDD_SIGN_ACCEPT);
                }
                // 如果已拒绝没有同步
                if (pinDuoDuoSignShop.getSignStatus() == 2){
                    pinDuoDuoSendSign.setSignOrderSn(pinDuoDuoSignShop.getSignOrderSn());
                    pinDuoDuoSendSign.setMallId(pinDuoDuoSignShop.getMallId());
                    pinDuoDuoSendSign.setServType(pinDuoDuoSignShop.getServType());
                    pinDuoDuoSendSign.setVerifyStatus(PinDuoDuoConsts.PDD_SIGN_REJECT);
                }

                // 发送请求
                String paramJson = JSON.toJSONString(pinDuoDuoSendSign, SerializerFeature.SortField.MapSortField);
                PinDuoDuoResponse response = pinDuoDuoService.sendRequestToPinDuoDuo(PinDuoDuoConsts.PDD_SERVICE_PATH, paramJson);
                if (Objects.isNull(response)){
                    log.info("【{}-API】 发送签约结果回传请求失败", PinDuoDuoConsts.CHANNEL_NAME);
                    return null;
                }

                if (!response.getSuccess()){
                    log.info("【{}-API】签约结果回传返回失败，code:【{}】，错误msg:【{}】",PinDuoDuoConsts.CHANNEL_NAME,
                            response.getErrorCode(), response.getErrorMsg());
                } else {    //如果拼多多返回成功，则改变同步状态
                    if (pinDuoDuoSignShop.getSignStatus() == 1){
                        pinDuoDuoSignShop.setSyncStatus(1);
                    }
                    if (pinDuoDuoSignShop.getSignStatus() == 2){
                        pinDuoDuoSignShop.setSyncStatus(2);
                    }
                    pinDuoDuoSignShop.setUpdater("系统");
                    try {
                        Integer result = pinDuoDuoSignShopService.modifyPinDuoDuoSignShopByMallId(pinDuoDuoSignShop);
                        if (result > 0) {
                            log.info("【{}】修改店铺同步状态成功，店铺id:[{}]，签约状态:[{}]，同步状态:[{}]",
                                    PinDuoDuoConsts.CHANNEL_NAME, pinDuoDuoSignShop.getMallId(),
                                    pinDuoDuoSignShop.getSignOrderSn(), pinDuoDuoSignShop.getSyncStatus());
                        } else {
                            log.info("【{}】修改店铺同步状态失败，店铺id:[{}]，签约状态:[{}]，同步状态:[{}]",
                                    PinDuoDuoConsts.CHANNEL_NAME, pinDuoDuoSignShop.getMallId(),
                                    pinDuoDuoSignShop.getSignOrderSn(), pinDuoDuoSignShop.getSyncStatus());
                        }
                    }catch (Exception e){
                        log.error("【{}】修改店铺签约信息失败，修改内容[{}]，异常[{}]", PinDuoDuoConsts.CHANNEL_NAME,
                                pinDuoDuoSignShop.toString(), e.getMessage());
                    }
                }
                log.info("#oms#pinduoduo_sign_notify#发送签约结果回传");
            }
        }
        return new Result(Action.EXECUTE_SUCCESS, "执行成功了!");
    }
}
*/
